package windbell.domain.risk.impl;

import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;
import windbell.domain.risk.RiskCommonIssue;
import windbell.domain.risk.RiskSubCategory;
import windbell.domain.risk.impl.BaseHasSimplePyImpl;
import windbell.domain.risk.impl.RiskSubCategoryImpl;
import windbell.domain.risk.proxy.RiskCommonIssueProxy;

@Entity
@DiscriminatorValue("RISKCOMMONISSUE_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "riskcommonissue")
public class RiskCommonIssueImpl extends BaseHasSimplePyImpl implements RiskCommonIssue {
  public RiskCommonIssueImpl() {
    super();
  }
  
  public RiskCommonIssueImpl(final RiskSubCategory subCategory) {
    super();
    this.subCategory = subCategory;
  }
  
  @JoinColumn(name = "subCategory_id")
  @ManyToOne(targetEntity = RiskSubCategoryImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RiskSubCategory subCategory;
  
  public RiskSubCategory getSubCategory() {
    return this.subCategory;
  }
  
  public static RiskCommonIssue create(final RiskSubCategory subCategory, final IObjectFactory objectFactory) {
    windbell.domain.risk.RiskCommonIssue riskCommonIssue = new windbell.domain.risk.impl.RiskCommonIssueImpl(
    	subCategory
    );
    objectFactory.create(riskCommonIssue);
    return riskCommonIssue;			
    
  }
  
  public static RiskCommonIssue createRiskCommonIssueImpl(final RiskSubCategory subCategory, final IObjectFactory objectFactory, final Procedure1<RiskCommonIssue> init) {
    windbell.domain.risk.RiskCommonIssue riskCommonIssue = new windbell.domain.risk.impl.RiskCommonIssueImpl(
    	subCategory
    );
    objectFactory.create(riskCommonIssue);
    init.apply(riskCommonIssue);
    return riskCommonIssue;			
    
  }
  
  public RiskCommonIssueProxy toProxy() {
    windbell.domain.risk.proxy.RiskCommonIssueProxy proxy = new windbell.domain.risk.proxy.RiskCommonIssueProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
